\hypertarget{group__nxbot__pwm}{
\section{PWM Library}
\label{group__nxbot__pwm}\index{PWM Library@{PWM Library}}
}


PWM library for applying different velocities to the motors in NXBOT.  


\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\#define \hyperlink{group__nxbot__pwm_gad24a782450af78b1984c2e6459890548}{PWM\_\-FREQUENCY\_\-16M}~1
\begin{DoxyCompactList}\small\item\em 16MHz PWM frequency. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__pwm_gae9e56c710ccdbc913067cf7324aa8fa4}{PWM\_\-FREQUENCY\_\-2M}~2
\begin{DoxyCompactList}\small\item\em 2MHz PWM frequency. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__pwm_gac792ff37b641e5d467a83d512e189cc6}{PWM\_\-FREQUENCY\_\-250K}~3
\begin{DoxyCompactList}\small\item\em 250kHz PWM frequency. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__pwm_gad42a8c8ba32b1915931302bd932eebeb}{PWM\_\-FREQUENCY\_\-62K}~4
\begin{DoxyCompactList}\small\item\em 62kHz PWM frequency. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__pwm_ga177dac768e68ba08d2724797c846955e}{PWM\_\-FREQUENCY\_\-15K}~5
\begin{DoxyCompactList}\small\item\em 15kHz PWM frequency. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__pwm_ga391fa1e490bd712720989b58fa0d9904}{PWM\_\-MAX}~127
\begin{DoxyCompactList}\small\item\em Max. value applicable to PWM hardware. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{group__nxbot__pwm_ga89212b075245454426b93c0f0a98900b}{pwm\_\-init} (unsigned char freq)
\begin{DoxyCompactList}\small\item\em Hardware initialization of the pwm module. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__pwm_ga3ad4a487f5e13d60ca4afd576938a44b}{pwm\_\-setFreq} (unsigned char freq)
\begin{DoxyCompactList}\small\item\em Sets the frequency of the PWM signal. \item\end{DoxyCompactList}\item 
unsigned char \hyperlink{group__nxbot__pwm_ga75b4d66479bc6b0a563251c8f18846dd}{pwm\_\-getFreq} (void)
\begin{DoxyCompactList}\small\item\em Gets the preconfigured frequency of the PWM signal. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__pwm_ga218725a2b447740d97be3970ab29c7e5}{pwm\_\-writeRight} (signed char right)
\begin{DoxyCompactList}\small\item\em Write desired PWM value for right motor. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__pwm_gaee380cd1b8aa28f7fdf34c634265bd68}{pwm\_\-writeLeft} (signed char left)
\begin{DoxyCompactList}\small\item\em Write desired PWM value for left motor. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__pwm_ga5ed6b6cdaae3da51bab8ad7cc311a255}{pwm\_\-write} (signed char left, signed char right)
\begin{DoxyCompactList}\small\item\em Write desired PWM value for both left and right motors. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
PWM library for applying different velocities to the motors in NXBOT. 
\begin{DoxyCode}
 #include <pwm.h> 
\end{DoxyCode}
 This module uses timer0 of the ATmega1281 microcontroller for generating the desired PWM signals. Timer0 is configured in {\itshape Free Running mode\/}, and it is constantly compared with two registers (OC0 and OC1), in order to toggle the logical state of two pins, where the PWM signals to the motors are connected. Another two signals are used in order to set the desired direction of the motor. For FORWARD direction use {\bfseries positive} values, for BACKWARD direction use {\bfseries negative} values. This library does not need to have the interrupts in order to function correctly, it is not an interrupt-\/driven module. 

\subsection{Define Documentation}
\hypertarget{group__nxbot__pwm_ga177dac768e68ba08d2724797c846955e}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!PWM\_\-FREQUENCY\_\-15K@{PWM\_\-FREQUENCY\_\-15K}}
\index{PWM\_\-FREQUENCY\_\-15K@{PWM\_\-FREQUENCY\_\-15K}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{PWM\_\-FREQUENCY\_\-15K}]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-FREQUENCY\_\-15K~5}}
\label{group__nxbot__pwm_ga177dac768e68ba08d2724797c846955e}


15kHz PWM frequency. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__pwm_ga3ad4a487f5e13d60ca4afd576938a44b}{pwm\_\-setFreq} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__pwm_gad24a782450af78b1984c2e6459890548}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!PWM\_\-FREQUENCY\_\-16M@{PWM\_\-FREQUENCY\_\-16M}}
\index{PWM\_\-FREQUENCY\_\-16M@{PWM\_\-FREQUENCY\_\-16M}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{PWM\_\-FREQUENCY\_\-16M}]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-FREQUENCY\_\-16M~1}}
\label{group__nxbot__pwm_gad24a782450af78b1984c2e6459890548}


16MHz PWM frequency. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__pwm_ga3ad4a487f5e13d60ca4afd576938a44b}{pwm\_\-setFreq} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__pwm_gac792ff37b641e5d467a83d512e189cc6}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!PWM\_\-FREQUENCY\_\-250K@{PWM\_\-FREQUENCY\_\-250K}}
\index{PWM\_\-FREQUENCY\_\-250K@{PWM\_\-FREQUENCY\_\-250K}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{PWM\_\-FREQUENCY\_\-250K}]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-FREQUENCY\_\-250K~3}}
\label{group__nxbot__pwm_gac792ff37b641e5d467a83d512e189cc6}


250kHz PWM frequency. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__pwm_ga3ad4a487f5e13d60ca4afd576938a44b}{pwm\_\-setFreq} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__pwm_gae9e56c710ccdbc913067cf7324aa8fa4}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!PWM\_\-FREQUENCY\_\-2M@{PWM\_\-FREQUENCY\_\-2M}}
\index{PWM\_\-FREQUENCY\_\-2M@{PWM\_\-FREQUENCY\_\-2M}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{PWM\_\-FREQUENCY\_\-2M}]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-FREQUENCY\_\-2M~2}}
\label{group__nxbot__pwm_gae9e56c710ccdbc913067cf7324aa8fa4}


2MHz PWM frequency. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__pwm_ga3ad4a487f5e13d60ca4afd576938a44b}{pwm\_\-setFreq} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__pwm_gad42a8c8ba32b1915931302bd932eebeb}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!PWM\_\-FREQUENCY\_\-62K@{PWM\_\-FREQUENCY\_\-62K}}
\index{PWM\_\-FREQUENCY\_\-62K@{PWM\_\-FREQUENCY\_\-62K}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{PWM\_\-FREQUENCY\_\-62K}]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-FREQUENCY\_\-62K~4}}
\label{group__nxbot__pwm_gad42a8c8ba32b1915931302bd932eebeb}


62kHz PWM frequency. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__pwm_ga3ad4a487f5e13d60ca4afd576938a44b}{pwm\_\-setFreq} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__pwm_ga391fa1e490bd712720989b58fa0d9904}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!PWM\_\-MAX@{PWM\_\-MAX}}
\index{PWM\_\-MAX@{PWM\_\-MAX}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{PWM\_\-MAX}]{\setlength{\rightskip}{0pt plus 5cm}\#define PWM\_\-MAX~127}}
\label{group__nxbot__pwm_ga391fa1e490bd712720989b58fa0d9904}


Max. value applicable to PWM hardware. 



\subsection{Function Documentation}
\hypertarget{group__nxbot__pwm_ga75b4d66479bc6b0a563251c8f18846dd}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!pwm\_\-getFreq@{pwm\_\-getFreq}}
\index{pwm\_\-getFreq@{pwm\_\-getFreq}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{pwm\_\-getFreq}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char pwm\_\-getFreq (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__pwm_ga75b4d66479bc6b0a563251c8f18846dd}


Gets the preconfigured frequency of the PWM signal. 

\begin{DoxyReturn}{Returns}
Frequency of the PWM signal. It is one of the PWM\_\-FREQUENCY\_\- constants defined above, e.g. PWM\_\-FREQUENCY\_\-15K 
\end{DoxyReturn}
\hypertarget{group__nxbot__pwm_ga89212b075245454426b93c0f0a98900b}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!pwm\_\-init@{pwm\_\-init}}
\index{pwm\_\-init@{pwm\_\-init}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{pwm\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void pwm\_\-init (
\begin{DoxyParamCaption}
\item[{unsigned char}]{freq}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__pwm_ga89212b075245454426b93c0f0a98900b}


Hardware initialization of the pwm module. 

Configures the PWM in order to control motor velocities. As this is not an interrupt-\/driven module, there is not need to call sei() function.


\begin{DoxyParams}{Parameters}
{\em freq} & Frequency of the PWM signal. It should be one of the PWM\_\-FREQUENCY\_\- constants defined above, e.g. PWM\_\-FREQUENCY\_\-15K \\
\hline
\end{DoxyParams}
\hypertarget{group__nxbot__pwm_ga3ad4a487f5e13d60ca4afd576938a44b}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!pwm\_\-setFreq@{pwm\_\-setFreq}}
\index{pwm\_\-setFreq@{pwm\_\-setFreq}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{pwm\_\-setFreq}]{\setlength{\rightskip}{0pt plus 5cm}void pwm\_\-setFreq (
\begin{DoxyParamCaption}
\item[{unsigned char}]{freq}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__pwm_ga3ad4a487f5e13d60ca4afd576938a44b}


Sets the frequency of the PWM signal. 


\begin{DoxyParams}{Parameters}
{\em freq} & Frequency of the PWM signal. It should be one of the PWM\_\-FREQUENCY\_\- constants configured above, e.g. PWM\_\-FREQUENCY\_\-15K \\
\hline
\end{DoxyParams}
\hypertarget{group__nxbot__pwm_ga5ed6b6cdaae3da51bab8ad7cc311a255}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!pwm\_\-write@{pwm\_\-write}}
\index{pwm\_\-write@{pwm\_\-write}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{pwm\_\-write}]{\setlength{\rightskip}{0pt plus 5cm}void pwm\_\-write (
\begin{DoxyParamCaption}
\item[{signed char}]{left, }
\item[{signed char}]{right}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__pwm_ga5ed6b6cdaae3da51bab8ad7cc311a255}


Write desired PWM value for both left and right motors. 


\begin{DoxyParams}{Parameters}
{\em left} & Desired PWM value for left motor. Same as in \hyperlink{group__nxbot__pwm_gaee380cd1b8aa28f7fdf34c634265bd68}{pwm\_\-writeLeft()}. \\
\hline
{\em right} & Desired PWM value for right motor. Same as in \hyperlink{group__nxbot__pwm_ga218725a2b447740d97be3970ab29c7e5}{pwm\_\-writeRight()}. \\
\hline
\end{DoxyParams}
\hypertarget{group__nxbot__pwm_gaee380cd1b8aa28f7fdf34c634265bd68}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!pwm\_\-writeLeft@{pwm\_\-writeLeft}}
\index{pwm\_\-writeLeft@{pwm\_\-writeLeft}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{pwm\_\-writeLeft}]{\setlength{\rightskip}{0pt plus 5cm}void pwm\_\-writeLeft (
\begin{DoxyParamCaption}
\item[{signed char}]{left}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__pwm_gaee380cd1b8aa28f7fdf34c634265bd68}


Write desired PWM value for left motor. 


\begin{DoxyParams}{Parameters}
{\em left} & Desired PWM value for left motor. The max value applicable is PWM\_\-MAX, which is 127. You can also set negative values for backward direction of the motor. \\
\hline
\end{DoxyParams}
\hypertarget{group__nxbot__pwm_ga218725a2b447740d97be3970ab29c7e5}{
\index{nxbot\_\-pwm@{nxbot\_\-pwm}!pwm\_\-writeRight@{pwm\_\-writeRight}}
\index{pwm\_\-writeRight@{pwm\_\-writeRight}!nxbot_pwm@{nxbot\_\-pwm}}
\subsubsection[{pwm\_\-writeRight}]{\setlength{\rightskip}{0pt plus 5cm}void pwm\_\-writeRight (
\begin{DoxyParamCaption}
\item[{signed char}]{right}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__pwm_ga218725a2b447740d97be3970ab29c7e5}


Write desired PWM value for right motor. 


\begin{DoxyParams}{Parameters}
{\em right} & Desired PWM value for right motor. The max value applicable is PWM\_\-MAX, which is 127. You can also set negative values for backward direction of the motor. \\
\hline
\end{DoxyParams}
